# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=py-bluez
_pkgname=pybluez
pkgver=0.22
pkgrel=4
pkgdesc="Python API for the BlueZ bluetooth stack"
url="http://karulis.github.io/pybluez/"
arch="all"
license="GPL-2.0-or-later"
makedepends="python2-dev python3-dev py3-setuptools py2-setuptools bluez-dev"
subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3"
source="$pkgname-$pkgver.tar.gz::https://github.com/karulis/$_pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	default_prepare

	# Soure files are modified during build with 2to3 tool, so we cannot
	# build it for both Python versions in the same location.
	local python; for python in python2 python3; do
		cp -r "$builddir" "$builddir-$python"
	done
}

build() {
	local python; for python in python2 python3; do
		cd "$builddir"-$python
		$python setup.py build
	done
}

package() {
	mkdir -p "$pkgdir"
}

_py2() {
	replaces="$pkgname"
	_py python2
}

_py3() {
	_py python3
}

_py() {
	local python="$1"
	pkgdesc="$pkgdesc (for $python)"
	install_if="$pkgname=$pkgver-r$pkgrel $python"

	cd "$builddir"-$python
	$python setup.py install --prefix=/usr --root="$subpkgdir"
}

sha512sums="5b35b9e0eae1c6ebabb29892fcff583479ac0627ad7d6549f3d2de90f89a1ba465b7452fa263045298ccfcf063ba070bfd346a6433b5567f8e3e646886017165  py-bluez-0.22.tar.gz"
